package code;
import models.Tree;
import models.TreeNode;
public class Convert {
    public TreeNode Solution(TreeNode pRootOfTree) {
        if(pRootOfTree == null){
            return null;
        }
        if(pRootOfTree.left==null && pRootOfTree.right==null){
            return pRootOfTree;
        }
        if(pRootOfTree.left!=null){
            TreeNode t = Solution(pRootOfTree.left);
            t.right = pRootOfTree;
            pRootOfTree.left = t;
        }
        if(pRootOfTree.right!=null){
            TreeNode r = Solution(pRootOfTree.right);
            r.right=pRootOfTree;
            return r;
        }
        return pRootOfTree;
    }
}
